﻿@using CubicFWNet.Data.Models
@model IEnumerable<CubicFWNet.Data.ViewModal.NewProductView>
@{
    var customer = ViewBag.Customer as Customer;
    var pid = ViewBag.PurchasePrintId;
}
<section class="content-header">
    <h1>
        采购单打印
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index", "Home")">首页</a></li>
        <li class="active"><a href="@Url.Action("PurchasePrint", "Purchase")">采购单打印</a></li>
    </ol>
</section>
<section class="content">
    <div class="box box-solid">
        <!-- /.box-header -->
        <div class="box-body">
            <div class="row">
                @if (Model != null)
                {
                    <form class="form-horizontal" id="frmedit" action="@Url.Action("UpdatePurchaseInfoPrint", "Purchase")" method="post">
                        <input type="hidden" id="StoreName" name="StoreName" value="" />
                        <input type="hidden" id="pid" name="pid" value="@pid" />

                        <div class="box-body">
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div id="json-content" class="col-md-12 ">
                                @*col-md-offset-1*@
                                <span class="btn btn-primary submitbtn" id="print" onclick="print()">打印</span>
                                <div class="form-group col-md-12" style="height: 1px;"></div>
                                <div id="footableF">
                                    <div class="form-group col-md-12" style="font-size: 25px; font-weight: 400; text-align: center">采&nbsp;购&nbsp;订&nbsp;单</div>
                                    <div style="display: inline-block; text-align: left; width: 70%">
                                        <div>采购方：北京永嘉信印刷有限公司</div>
                                        <div>电话：010-56495200-822</div>
                                        <div>传真：010-56495165</div>
                                        <div>联系人：</div>
                                    </div>
                                    <div style="display: inline-block; text-align: left; width: 25%">
                                        @if (customer != null && !string.IsNullOrEmpty(customer.Principal))
                                        {
                                            <div>供货方：@customer.Name</div>
                                            var principal = Newtonsoft.Json.JsonConvert.DeserializeObject<List<dynamic>>(customer.Principal);
                                            var sh = principal.FirstOrDefault(a => a.name == "SH");
                                            var cg = principal.FirstOrDefault(a => a.name == "CG");
                                            if (sh != null)
                                            {
                                                <div>电话：@sh.value</div>
                                            }
                                            else
                                            {
                                                <div>电话：</div>
                                            }
                                            <div>传真：</div>
                                            if (cg != null)
                                            {
                                                <div>联系人：@cg.value</div>
                                            }
                                            else
                                            {
                                                <div>联系人：</div>
                                            }
                                        }
                                        else
                                        {
                                            <div>供货方：</div>
                                            <div>电话：</div>
                                            <div>传真：</div>
                                            <div>联系人：</div>
                                        }
                                    </div>
                                    <br /><br />
                                    <table class="footable table table-stripped table-bordered table-hover" id="footable">
                                        <thead>
                                            <tr>
                                                <th data-sort-ignore="true" style="width: 50px;">
                                                    序号
                                                </th>
                                                <th data-sort-ignore="true">
                                                    名称
                                                </th>
                                                <th data-sort-ignore="true">
                                                    规格
                                                </th>
                                                <th data-sort-ignore="true" style="width: 80px;">
                                                    单位
                                                </th>
                                                <th data-sort-ignore="true">
                                                    数量
                                                </th>
                                                <th data-sort-ignore="true">
                                                    单价（含税）
                                                </th>
                                                <th data-sort-ignore="true">
                                                    合计
                                                </th>
                                                <th data-sort-ignore="true">
                                                    备注
                                                </th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @if (Model != null)
                                            {
                                                var num = 0;
                                                decimal totalPrice = 0;
                                                foreach (var item in Model)
                                                {
                                                    var format = item.ProductSizeWidth + "*" + item.ProductSizeLenth;
                                                    decimal price = item.CostPrice * item.ProductAmount;
                                                    totalPrice += price;
                                                    <tr class="tr">
                                                        <td>
                                                            @num
                                                        </td>
                                                        <td>
                                                            @item.ProductName
                                                        </td>
                                                        <td>
                                                            @format
                                                        </td>
                                                        <td>
                                                            @item.ProductUnit
                                                        </td>
                                                        <td>
                                                            @item.ProductAmount
                                                        </td>
                                                        <td>
                                                            @item.CostPrice
                                                        </td>
                                                        <td>
                                                            @price.ToString("f2")
                                                        </td>
                                                        <td style="width: 200px;">
                                                            @item.Memo
                                                        </td>
                                                    </tr>
                                                    num++;
                                                }
                                                <tr>
                                                    <td colspan="8">
                                                        采购总价：@totalPrice.ToString("f2")
                                                    </td>
                                                </tr>
                                            }
                                        </tbody>
                                    </table>

                                    <div style="display: inline-block; text-align: left; width: 70%">
                                        <div>备 注</div>
                                        <div>（1）所有贷款均以人名币结算</div>
                                        <div>（2）交货日期：<span id="jiaot"></span></div>
                                        <div>（2）交货地点：<span id="jiaoad"></span></div>
                                        <div>（3）订单号：<span id="jiaoord"></span></div>
                                    </div>
                                    <br /><br />
                                    <div style="display: inline-block; text-align: left; width: 70%">
                                        <div>采购人：</div>
                                        <div>日期：</div>
                                        <div>签章：</div>
                                    </div>
                                    <div style="display: inline-block; text-align: left; width: 25%">
                                        <div>供货人：</div>
                                        <div>日期：</div>
                                        <div>签章：</div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                        </div>
                        <div class="box-footer" style="width: 80%; margin-left: 20px;">
                            <a role="button" href="javascript:void(0)" class="btn btn-primary submitbtn" onclick="formsubmit()">打印完成</a>
                            <a class="btn btn-primary submitbtn" href="@Url.Action("PurchasePrint", "Purchase")">返回</a>
                        </div>

                        <div class="form-group col-md-6">
                            <label class="col-sm-3 control-label">交货日期</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="jiaotime" />
                            </div>
                        </div>
                        <div class="form-group col-md-6">
                            <label class="col-sm-3 control-label">交货地点</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="jiaoaddre" />
                            </div>
                        </div>
                        <div class="form-group col-md-6">
                            <label class="col-sm-3 control-label">订单号</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="jiaoorder" />
                            </div>
                        </div>
                    </form>


                }
            </div>
        </div>
    </div>
</section>

<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">数据加载中，请稍后…</div>
</div>

@section Scripts{
    <script src="~/Scripts/jquery.jqprint-0.3.js"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $("#frmedit").validate({
                submitHandler: function (form) {
                    var postData = $(form).formSerialize();
                    $.submitForm({
                        url: $(form).attr("action"),
                        param: postData,
                        success: function () {
                            //$.reload();
                            $.modalAlert("操作成功", "success");
                            window.location.href = '@Url.Action("PurchasePrint", "Purchase")';
                        }
                    });
                }
            });

            $('#footable').footable();
            //日期控件
            $(".Timedatepicker").datepicker({
                autoclose: true,
                language: 'zh', //汉化
                format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
                minView: "month" //选择日期后，不会再跳转去选择时分秒
            });
            /*$(document).on("change", "#StoreType", function () {
                var storeTypeName = this.options[this.selectedIndex].innerHTML;
                $("#StoreName").val(storeTypeName);
            });
            $("#StoreType").change(); //第一个默认点击状态*/

        });

        function formsubmit() {
            $("#frmedit").submit();
        }


        $(".okeydown").on("keydown", function () {
            var k = event.keyCode;
            if ((k <= 57 && k >= 48) || (k <= 105 && k >= 96) || (k == 8) || (k == 110) || (k == 190)) {
                return true;
            } else {
                return false;
            }
        });

        $("#jiaotime").keyup(function() {
            var content = $("#jiaotime").val();
            $("#jiaot").text(content);
        });
        $("#jiaoaddre").keyup(function () {
            var content = $("#jiaoaddre").val();
            $("#jiaoad").text(content);
        });
        $("#jiaoorder").keyup(function () {
            var content = $("#jiaoorder").val();
            $("#jiaoord").text(content);
        });

        function print() {
            $("#footableF").jqprint();
        }

        /* $("#printContainer").jqprint({
             debug: false, //如果是true则可以显示iframe查看效果（iframe默认高和宽都很小，可以再源码中调大），默认是false
             importCSS: true, //true表示引进原来的页面的css，默认是true。（如果是true，先会找$("link[media=print]")，若没有会去找$("link")中的css文件）
             printContainer: true, //表示如果原来选择的对象必须被纳入打印（注意：设置为false可能会打破你的CSS规则）。
             operaSupport: true//表示如果插件也必须支持歌opera浏览器，在这种情况下，它提供了建立一个临时的打印选项卡。默认是true
         });*/
    </script>
}